package com.haixiaoke.saas.enterprise.house.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.SubHouse;
import com.haixiaoke.saas.house.service.ISubHouseService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋子房间Controller
 *
 * @author panda
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/enterprise/house/subHouse")
public class EnterpriseSubHouseController extends BaseController {
    @Autowired
    private ISubHouseService subHouseService;

    /**
     * 查询房屋子房间列表
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subHouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubHouse subHouse) {
        startPage();
        List<SubHouse> list = subHouseService.selectSubordinateHouseList(subHouse);
        return getDataTable(list);
    }

    /**
     * 导出房屋子房间列表
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subHouse:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubHouse subordinateHouse) {
        List<SubHouse> list = subHouseService.selectSubordinateHouseList(subordinateHouse);
        ExcelUtil<SubHouse> util = new ExcelUtil<SubHouse>(SubHouse.class);
        util.exportExcel(response, list, "房屋子房间数据");
    }

    /**
     * 获取房屋子房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subHouse:query')")
    @GetMapping(value = "/{subHouseId}")
    public AjaxResult getInfo(@PathVariable("subHouseId") String subordinateHouseId) {
        return success(subHouseService.selectSubordinateHouseBySubordinateHouseId(subordinateHouseId));
    }

    /**
     * 新增房屋子房间
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subHouse:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SubHouse subordinateHouse) {
        return toAjax(subHouseService.insertSubordinateHouse(subordinateHouse));
    }

    /**
     * 修改房屋子房间
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subordinateHouse:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SubHouse subordinateHouse) {
        return toAjax(subHouseService.updateSubordinateHouse(subordinateHouse));
    }

    /**
     * 删除房屋子房间
     */
    @PreAuthorize("@ss.hasPermi('saas-business:subordinateHouse:remove')")
	@DeleteMapping("/{subordinateHouseIds}")
    public AjaxResult remove(@PathVariable String[] subordinateHouseIds) {
        return toAjax(subHouseService.deleteSubordinateHouseBySubordinateHouseIds(subordinateHouseIds));
    }
}
